Skip to content

Conversation

@slonopotamus
Copy link

Instead, just return an error, so it's up to the calling code how to handle it.

This is an API-breaking change.

Instead, just return an error, so it's up to the calling code how to handle it.

This is an API-breaking change.

Signed-off-by: Marat Radchenko <[email protected]>
// Current returns the current process' console
func Current() (c Console) {
var err error
func Current() (c Console, err error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of renaming this, can we add an additional constructor that returns the error? Something like:

func GetCurrent() (Console, error)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we shouldn't have to worry about the breaking change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 this code may be incorporated in various projects, and we should try to avoid breaking this signature (it may be complex to resolve otherwise). I don't have a good suggestion for the new function's name (perhaps someone else has?). Perhaps TryCurrentConsole() ?

That said, it looks like Current() is a very small wrapper around ConsoleFromFile(), so to some extent, users would already be able to work around this.

We should improve the GoDoc for Current() though!

  • Outline what it does (tries the standard-streams (STDERR, STDOUT, STDIN to get the console)
  • It panics when it fails to detect a console in any of those.
  • Point users to the alternative / equivalent using ConsoleFromFile

@slonopotamus
Copy link
Author

slonopotamus commented Feb 5, 2024

I'm not interested in pushing these changes forward anymore. My goal was to use containerd/console on macOS, but it turned out to be broken a lot (see #80). So I instead switched to creack/pty.

@slonopotamus slonopotamus deleted the do-not-panic branch February 5, 2024 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants